using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace MyCustomControl
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>

    public partial class Window1 : Window
    {
        Boolean ResizeInProcess = false;
        public Window1()
        {
            InitializeComponent();
        }

        private void Resize_Init( object sender, MouseButtonEventArgs e )
        {
            Rectangle senderRect = sender as Rectangle;

            if( senderRect != null )
            {
                ResizeInProcess = true;
                senderRect.CaptureMouse();
            }
        }

        private void Resize_End( object sender, MouseButtonEventArgs e )
        {
            Rectangle senderRect = sender as Rectangle;
            if( senderRect != null )
            {
                ResizeInProcess = false; ;
                senderRect.ReleaseMouseCapture();
            }

        }

        private void Resizeing_Form( object sender, MouseEventArgs e )
        {
            if( ResizeInProcess )
            {
                Rectangle senderRect = sender as Rectangle;
                if( senderRect != null )
                {
                    double width = e.GetPosition( this ).X;
                    double height = e.GetPosition( this ).Y;
                    senderRect.CaptureMouse();
                    if( ( string ) senderRect.Tag == "ResizeWidth" )
                    {
                        width += 5;
                        if( width > 0 )
                            this.Width = width;
                    }
                    else
                        if( ( string ) senderRect.Tag == "ResizeHeigth" )
                        {
                            height += 5;
                            if( height > 0 )
                                this.Height = height;
                        }
                }
            }
        }


        private void LeftMouseDown_Event( object sender, System.Windows.Input.MouseButtonEventArgs e )
        {
            this.DragMove();
        }



    }
}